﻿using NewsCollection.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewsCollection.Common.Service
{
    class DataManual

    {

        DataContext db = new DataContext("name=news");
        ProcessDb pdb = new ProcessDb();
        private void Save(string[] list,Boolean haveParent,string myIdParent,string nameParent)
        {
            
            for (int i = 0; i < list.Count(); i++)
            {
                CategoryManuals cama = new CategoryManuals();
                cama.MyId = list[i];
                cama.MyName = list[i];
                if (haveParent == true)
                {
                    var parent = pdb.SearchCategoryManuals(nameParent);
                    cama.ParentCategoryManual = parent;
                }
                    
                else
                    cama.ParentCategoryManual = null;
                pdb.SaveCategoryManual(cama);
            }
        }
        public void AddToCategoryManual()
        {

           


            string[] MyNames = { "Thoitrang", "Sao", "Teen", "Lamdep", "Goctamsu", };
            string[] Sub1 = { "Tinthoitrang", "Bosuutap", "Thegioithoitrang" };
            string[] Sub2 = { "Tinsao", "Thoitrangsao", };
            string[] Sub3 = { "Tinhot", "Teenthoitrang", };
            string[] Sub4 = { "Lamdepmoingay", "Meohay", };
            string[] Sub5 = { "Tinhyeu", "Gioitinh" };
            Save(MyNames, false,0+"","");
            Save(Sub1, true, 0 + "", MyNames[0]);
            Save(Sub2, true, 1 + "", MyNames[1]);
            Save(Sub3, true, 2 + "", MyNames[2]);
            Save(Sub4, true, 3 + "", MyNames[3]);
            Save(Sub5, true, 4 + "", MyNames[4]);
        }
        public void AddToManu()
        {
            string[] name = { "afamily.vn", "kenh14.vn", "news.zing.vn", "ya.vn", "ngoisao.vn", "2sao.vn", "elle.vn", "dantri.com.vn" ,
                            "giadinh.vn","tinmoi.vn"};
            for (int i = 0; i < name.Count(); i++)
            {
                Manufactory ma = new Manufactory();
                ma.Name = name[i];
                ma.Url = "http://"+name[i];
                pdb.SaveManufactory(ma);
            }
        }

    }
}
